package com.ss.android.article.base.feature.detail2.video.a;

import android.os.Build;
import android.text.TextPaint;
import android.view.ViewTreeObserver;

import com.ss.android.action.a.a.Comment;
import com.ss.android.common.lib.MobClickCombiner;

import java.util.HashSet;
import java.util.Iterator;
import java.util.List;

import org.json.JSONException;
import org.json.JSONObject;

public final class k implements ViewTreeObserver.OnGlobalLayoutListener {
    private final VideoDetailExtraHolder c;
    private final List a;
    private final String b;

    public k(VideoDetailExtraHolder arg1, List arg2, String arg3) {
        this.c = arg1;
        this.a = arg2;
        this.b = arg3;

    }

    public final void onGlobalLayout() {
        int v1_1;
        String v6;
        Object v0;
        if (Build.VERSION.SDK_INT >= 16) {
            this.c.mTxtReprintPGC.getViewTreeObserver().removeOnGlobalLayoutListener(((ViewTreeObserver.OnGlobalLayoutListener) this));
        } else {
            this.c.mTxtReprintPGC.getViewTreeObserver().removeGlobalOnLayoutListener(((ViewTreeObserver.OnGlobalLayoutListener) this));
        }

        TextPaint v2 = this.c.mTxtReprintPGC.getPaint();
        Iterator v1 = this.a.iterator();
        StringBuilder v3 = new StringBuilder();
        StringBuilder v4 = new StringBuilder();
        HashSet v5 = new HashSet();
        while (true) {
            if (v1.hasNext()) {
                v0 = v1.next();
                if (v5.contains(((Comment) v0).mediaId)) {
                    continue;
                }

                v5.add(((Comment) v0).mediaId);
                v6 = ((Comment) v0).mediaName;
                int v7 = this.c.mTxtReprintPGC.getWidth();
                if (v2.measureText(String.format(this.b, new Object[]{v3 + "、" + v6})) > (((float) v7))) {
                    v1_1 = v6.length();
                    if (v3.length() != 0) {

                    } else {
                        while (v2.measureText(String.format(this.b, new Object[]{v6.substring(0, v1_1) + "..."})) > (((float) v7))) {
                            --v1_1;
                        }

                        v3.append(v6.substring(0, v1_1));
                        v3.append("...");
                        v4.append(((Comment) v0).mediaId);
                    }
                } else {
                    if (v3.length() > 0) {
                        v3.append("、");
                    }

                    v3.append(v6);
                    if (v4.length() > 0) {
                        v4.append(",");
                    }

                    v4.append(((Comment) v0).mediaId);
                    continue;
                }
            }

            break;
        }

        this.c.mTxtReprintPGC.setText(String.format(this.b, v3.toString()));
        JSONObject v8 = new JSONObject();
        try {
            v8.put("media_ids", v4.toString());
        } catch (JSONException v0_1) {
            v0_1.printStackTrace();
        }

        MobClickCombiner.onEvent(this.c.mContext, "video", "show_zz_comment", this.c.mArticle.groupId, this.c.mArticle.itemId, v8);
    }
}

